package com.tang.algorithm.binaryserch;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * @author tlm
 * @Description
 * @date 2020/7/7 6:30 下午
 */
public class Mst1005 {
	public static void main(String[] args) {

		String[] s = { "DirNnILhARNS hOYIFB", "SM ", "YSPBaovrZBS", "evMMBOf", "mCrS", "oRJfjw gwuo", "xOpSEXvfI"};
		System.out.println(findString(s, "mCrS"));
	}

	public static int findString(String[] words, String s) {
		HashMap<String, Integer> hashMap = new HashMap<>();
		List<String> list = new ArrayList<>();
		for (int i = 0; i < words.length; i++) {
			if (!"".equals(words[i])) {
				hashMap.put(words[i], i);
				list.add(words[i]);
			}
		}
		int left = 0, right = list.size() - 1;
		while (left <= right) {
			int mid = (left + right) >>> 1;
			if (list.get(mid).equals(s)) {
				return hashMap.get(list.get(mid));
			} else if (list.get(mid).compareTo(s) > 0) {
				right = mid - 1;
			} else if (list.get(mid).compareTo(s) < 0) {
				left = mid + 1;
			}
		}
		return -1;
	}
}
